<script setup>
import { Close } from "@element-plus/icons-vue";

const props = defineProps({
  title: {
    type: String,
    default: "",
  },
  cancelText: {
    type: String,
    default: "取消",
  },
  confirmText: {
    type: String,
    default: "确定",
  },
  showCancel: {
    type: Boolean,
    default: true,
  },
  showConfirm: {
    type: Boolean,
    default: true,
  },
  loading: {
    type: Boolean,
    default: false,
  },
  width: {
    type: Number,
    default: 0,
  },
});
const emits = defineEmits(["close", "confirm"]);
const close = () => {
  emits("close");
};
const confirm = () => {
  emits("confirm");
};
</script>

<template>
  <div class="modal">
    <div class="modal-content" :style="{ width: width ? width + 'px' : 'auto' }">
      <div class="header">
        <img src="@/assets/modal-icon.png" alt="" />
        <span>{{ title }}</span>
        <el-icon class="close-icon" @click="close"><Close /></el-icon>
      </div>
      <div class="content">
        <slot name="content"></slot>
      </div>
      <div class="btns" v-if="showCancel || showConfirm">
        <span class="cancel" v-if="showCancel" @click="close">{{ cancelText }}</span>
        <el-button
          class="confirm"
          v-if="showConfirm"
          @click="confirm"
          :loading="loading"
          :disabled="loading"
          >{{ confirmText }}</el-button
        >
      </div>
    </div>
  </div>
</template>

<style scoped lang="scss">
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-content {
  background: #fff;
  border-radius: 12px 12px 12px 12px;
  padding: 20px;
  min-width: 300px;
}
.header {
  display: flex;
  align-items: center;
  margin-bottom: 8px;
  img {
    width: 20px;
    height: 20px;
    margin-right: 4px;
    position: relative;
    top: 1px;
  }
  span {
    flex: 1;
    font-size: 16px;
    font-weight: 600;
    color: #191e28;
  }
  .close-icon {
    font-size: 16px;
    cursor: pointer;
  }
}
.btns {
  padding: 16px 0 0;
  display: flex;
  justify-content: flex-end;
  span {
    cursor: pointer;
    padding: 6px 25px;
    border-radius: 8px 8px 8px 8px;
  }
  .cancel {
    background: #fff;
    border: 1px solid rgba(25, 30, 40, 0.08);
  }
  .confirm {
    background: #1dbf73;
    color: #fff;
    margin-left: 12px;
    width: 80px;
    height: 32px;
    border: none;
    border-radius: 8px 8px 8px 8px;
  }
}
</style>
